package com.xh.audit.controller.project;

import com.mybatisflex.core.paginate.Page;
import com.xh.audit.entity.project.ProjectLaborDivision;
import com.xh.audit.service.ProjectLaborDivisionService;
import com.xh.audit.vo.webform.ProjectLaborDivisionQuery;
import com.xh.common.R;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import java.util.List;

/**
 * <p>
 * 项目人员分工;项目和审计人员关联表 前端控制器
 * </p>
 *
 * @author lhl
 * @since 2023-10-19
 */
@RestController
@RequestMapping("/project-labor-division")
@RequiredArgsConstructor
@Validated
public class ProjectLaborDivisionController {
    private final ProjectLaborDivisionService projectLaborDivisionService;

    @PostMapping("/save")
    public R<ProjectLaborDivision> save(@RequestBody
                                        @Validated
                                                ProjectLaborDivision tosave) {
        boolean saveFlag = projectLaborDivisionService.saveOrUpdate(tosave);

        if (saveFlag) {
            return R.success(projectLaborDivisionService.getById(tosave.getId()));
        }
        return R.failed("保存失败");
    }

    /**
     * 查人员的  可用于人员存在校验
     * @param queryPage
     * @return
     */
    @PostMapping("/queryByPage")
    public R<Page<ProjectLaborDivision>> query(@RequestBody
                                               @Validated
                                                       ProjectLaborDivisionQuery queryPage) {
        Page<ProjectLaborDivision> page1 = projectLaborDivisionService.page(queryPage.getPageInfo(), queryPage.queryWrapperBuild());
        return R.success(page1);
    }

    @PostMapping("/del")
    public R<ProjectLaborDivision> del(@RequestBody
                                       @Validated
                                       @NotEmpty(message = "ids 集合不能空")
                                               List<Integer> ids) {
        projectLaborDivisionService.removeByIds(ids);
        return R.success("删除成功");
    }


}
